package com.ddx.controller.core;

import com.ddx.common.exception.ResultModel;
import com.ddx.dto.CompanyDto;
import com.ddx.service.CompanyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: liyuxiang
 * @create: 2019-01-06
 */
@RestController
@RequestMapping(value = "/app/company")
public class CompanyController {

    private static final Logger logger = LoggerFactory.getLogger(CompanyController.class);

    @Autowired
    CompanyService companyService;

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/register")
    public ResultModel register(HttpServletRequest request, @RequestBody CompanyDto companyDto) {
        try {
            int userId = Integer.parseInt(request.getHeader("userId"));
            return companyService.register(userId, companyDto);
        } catch (Exception e) {
            logger.error("register fail", e);
            return ResultModel.getErrorInstance("注册失败，请稍后重试");
        }
    }

}
